﻿using System;
using System.Collections.Generic;
using System.Text;
using Wangzeran.CodeMaker.Core.Tag;

namespace Wangzeran.CodeMaker.PlugIns.Util
{
    /// <summary>
    /// 缓存容器
    /// </summary>
    public class CacheContainers
    {
        /// <summary>
        /// 清空缓存
        /// </summary>
        public static void CleanCache()
        {
            CacheContainers.pythonScriptEngines = null;
            CacheContainers.tags = null;
            CacheContainers.templates = null;
            CacheContainers.variables = null;
        }


        #region 脚本引擎容器

        /// <summary>
        /// 脚本引擎容器
        /// </summary>
        private static IDictionary<string, PythonScriptEngine> pythonScriptEngines =
                                                    new Dictionary<string, PythonScriptEngine>();
        /// <summary>
        /// 获取脚本引擎容器
        /// </summary>
        public static IDictionary<string, PythonScriptEngine> PythonScriptEngines
        {
            get
            {
                if (pythonScriptEngines == null)
                {
                    pythonScriptEngines = new Dictionary<string, PythonScriptEngine>();
                }
                return CacheContainers.pythonScriptEngines;
            }
        }

        #endregion


        #region 自定义变量容器

        /// <summary>
        /// 自定义变量容器
        /// </summary>
        private static IDictionary<string, string> variables = new Dictionary<string, string>();
        /// <summary>
        /// 获取自定义变量容器
        /// </summary>
        public static IDictionary<string, string> Variables
        {
            get
            {
                if (CacheContainers.variables == null)
                {
                    CacheContainers.variables = new Dictionary<string, string>();
                }
                return CacheContainers.variables;
            }
        }

        #endregion


        #region 模板容器

        /// <summary>
        /// 模板容器
        /// </summary>
        private static IDictionary<string, string[]> templates = new Dictionary<string, string[]>();
        /// <summary>
        /// 获取模板容器
        /// </summary>
        public static IDictionary<string, string[]> Templates
        {
            get
            {
                if (templates == null)
                {
                    templates = new Dictionary<string, string[]>();
                }
                return CacheContainers.templates; 
            }
        }

        #endregion


        #region 标签容器

        /// <summary>
        /// 标签容器
        /// </summary>
        private static IDictionary<string, ITag> tags = new Dictionary<string, ITag>();
        /// <summary>
        /// 获取标签容器
        /// </summary>
        public static IDictionary<string, ITag> Tags
        {
            get 
            {
                if (tags == null)
                {
                    tags = new Dictionary<string, ITag>();
                }
                return CacheContainers.tags; 
            }
        }

        #endregion
    }
}
